<script setup lang="ts">

import SAside from '@/components/SAside.vue'
import { RouterView, useRouter } from 'vue-router'
import { useLayoutStore } from '@/stores/layout'
import { computed, onMounted } from 'vue'
import { useAuthStore } from '@/stores/auth'
import STop from '@/components/STop.vue'
import { useMenuStore } from '@/stores/menu'
import { routeMenuApi } from '@/api/menu'
import { ResultData } from '@/api/service'
import { RouteMenu } from '@/type/Menu'

const router = useRouter()
const { accessToken } = useAuthStore()
const layoutStore = useLayoutStore()
const { setDynamic, dynamic } = useMenuStore()

const menuStore = useMenuStore()

let include = computed(() => menuStore.tab.map(it => it.componentId))

let side = computed(() => layoutStore.side)

onMounted(() => {
  // 当系统中不存在 token 时认定未登录，跳转至登录页面
  if (accessToken == null || accessToken === '') {
    router.push("/login")
    return
  }

})


</script>

<template>
  <el-container>
    <el-aside class="s-aside" :width="side ? '200px' : '64px'">
      <s-aside />
    </el-aside>
    <el-container class="s-body">

      <el-header height="100px" class="s-header">
        <s-top/>
      </el-header>
      <el-main class="s-main">
        <el-scrollbar>
          <router-view v-slot="{ Component }">
            <keep-alive :include="include">
              <component :is="Component" />
            </keep-alive>
          </router-view>
        </el-scrollbar>
      </el-main>
    </el-container>
  </el-container>
</template>

<style scoped>

.s-header {
  padding: 0;
}

.s-aside {
  transition: all 0.3s ease;
  background: var(--sidebar-bg, var(--el-color-primary-dark-2));
  box-shadow: 2px 0 8px rgba(0, 0, 0, 0.15);
  border-right: none;
}

.s-body {
  height: 100vh;
}

.s-main {
  padding: 15px;
}

</style>